<div class="container">
  <div class="page-header">
    <h1 class="page-title">
      工作台
    </h1>
  </div>
  <div class="row row-cards">
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            6%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.where(state: :pending).count %></div>
          <div class="text-muted mb-4">待付款订单</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-red">
            -3%
            <i class="fe fe-chevron-down"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.where(state: :checkouted).count %></div>
          <div class="text-muted mb-4">待发货订单</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            9%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.where(state: :completed, is_evaluated: false).count %></div>
          <div class="text-muted mb-4">待评价订单</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            9%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.today.count %></div>
          <div class="text-muted mb-4">今日订单</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            3%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.today.sum(:total_fee) %></div>
          <div class="text-muted mb-4">今日销售额</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            9%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.yesterday.count %></div>
          <div class="text-muted mb-4">昨天订单</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            3%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.yesterday.sum(:total_fee) %></div>
          <div class="text-muted mb-4">昨天销售额</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            9%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.by_week.count %></div>
          <div class="text-muted mb-4">本周订单数</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            3%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.by_week.sum(:total_fee) %></div>
          <div class="text-muted mb-4">本周销售额</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            9%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.by_month.count %></div>
          <div class="text-muted mb-4">本月订单数</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-green">
            3%
            <i class="fe fe-chevron-up"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.by_month.sum(:total_fee) %></div>
          <div class="text-muted mb-4">本月销售额</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-red">
            -1%
            <i class="fe fe-chevron-down"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.balance %></div>
          <div class="text-muted mb-4">结余</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-red">
            -2%
            <i class="fe fe-chevron-down"></i>
          </div>
          <div class="h1 m-0"><%= @current_shoper.shop.orders.count %></div>
          <div class="text-muted mb-4">总订单数</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-red">
            -1%
            <i class="fe fe-chevron-down"></i>
          </div>
          <div class="h1 m-0">621</div>
          <div class="text-muted mb-4">总销售额</div>
        </div>
      </div>
    </div>
    <div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-red">
            -1%
            <i class="fe fe-chevron-down"></i>
          </div>
          <div class="h1 m-0"><%= current_shoper.shop.spus.where(published: true).count %></div>
          <div class="text-muted mb-4">出售中商品</div>
        </div>
      </div>
    </div><div class="col-6 col-sm-4 col-lg-2">
      <div class="card">
        <div class="card-body p-3 text-center">
          <div class="text-right text-red">
            -1%
            <i class="fe fe-chevron-down"></i>
          </div>
          <div class="h1 m-0"><%= current_shoper.shop.spus.count %></div>
          <div class="text-muted mb-4">商品总数</div>
        </div>
      </div>
    </div>
  </div>
  <div class="row row-cards">
    <div class="col-lg-6">
      <div class="card">
        <div class="card-header">
          <h3 class="card-title">待发货订单</h3>
        </div>
        <div class="table-responsive">
          <table class="table card-table table-striped table-vcenter">
            <thead>
              <tr>
                <th>订单编号</th>
                <th>总价</th>
                <th>下单日期</th>
                <th></th>
              </tr>
            </thead>
            <tbody>
              <% @current_shoper.shop.orders.where(state: :checkouted).order("updated_at DESC").limit(5).each do |order| %>
              <tr>
                <td><%= order.trade_no %></td>
                <td><%= order.total_fee %></td>
                <td class="text-nowrap"><%= formattime(order.created_at, unit: "day") %></td>
                <td class="w-1"><a href="<%= edit_shop_order_path(order) %>" class="icon"><i class="fe fe-edit"></i></a></td>
              </tr>
              <% end %>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div class="col-lg-6">
      <div class="card">
        <div class="card-header">
          <h3 class="card-title">申请售后订单</h3>
        </div>
        <div class="table-responsive">
          <table class="table card-table table-striped table-vcenter">
            <thead>
              <tr>
                <th>订单编号</th>
                <th>总价</th>
                <th>下单日期</th>
                <th></th>
              </tr>
            </thead>
            <tbody>
              <% @current_shoper.shop.orders.where(state: :after_sale).order("updated_at DESC").limit(5).each do |order| %>
              <tr>
                <td><%= order.trade_no %></td>
                <td><%= order.total_fee %></td>
                <td class="text-nowrap"><%= formattime(order.created_at, unit: "day") %></td>
                <td class="w-1"><a href="<%= edit_shop_order_path(order) %>" class="icon"><i class="fe fe-edit"></i></a></td>
              </tr>
              <% end %>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div class="col-lg-6">
      <div class="card">
        <div class="card-header">
          <h3 class="card-title">商品销售排行</h3>
        </div>
        <div class="table-responsive">
          <table class="table card-table table-striped table-vcenter">
            <thead>
              <tr>
                <th>商品名称</th>
                <th>销售量</th>
                <th>所属分类</th>
                <th></th>
              </tr>
            </thead>
            <tbody>
              <% @current_shoper.shop.spus.order("sales_volume DESC").limit(5).each do |spu| %>
              <tr>
                <td><%= spu.name %></td>
                <td><%= spu.sales_volume %></td>
                <td class="text-nowrap"><%= spu.shop_category.name %></td>
                <td class="w-1"><a href="<%= shop_spu_path(spu) %>" class="icon"><i class="fe fe-chevron-right"></i></a></td>
              </tr>
              <% end %>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div class="col-lg-6">
      <div class="card">
        <div class="card-header">
          <h3 class="card-title">已售完商品</h3>
        </div>
        <div class="table-responsive">
          <table class="table card-table table-striped table-vcenter">
            <thead>
              <tr>
                <th>商品名称</th>
                <th>SKU编号</th>
                <th>所属分类</th>
                <th></th>
              </tr>
            </thead>
            <tbody>
              <% Sku.joins(:spu).where("spus.shop_id = ? AND on_hand_count = 0", @current_shoper.shop_id).limit(5).each do |sku| %>
              <tr>
                <td><%= sku.spu.name %></td>
                <td><%= sku.name %></td>
                <td class="text-nowrap"><%= sku.spu.shop_category.name %></td>
                <td class="w-1"><a href="<%= shop_spu_path(sku.spu) %>" class="icon"><i class="fe fe-chevron-right"></i></a></td>
              </tr>
              <% end %>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>